list-[id].vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 二级标题-->
  10. <HomeListSecondaryHeading v-if="parent_name != ''" :name="parent_name" :nav="secondNav" :pinyin="parent_pinyin">
  11. </HomeListSecondaryHeading>
  12. <!-- 资讯列表 -->
  13. <main class="index_main">
  14. <!-- 面包屑导航 -->
  15. <div class="breadcrumb">
  16. <div class="inner">
  17. <span class="location">当前位置:</span>
  18. <el-breadcrumb :separator-icon="ArrowRight">
  19. <el-breadcrumb-item>
  20. <NuxtLink to="/">首页</NuxtLink>
  21. </el-breadcrumb-item>
  22. <el-breadcrumb-item v-if="parent_name != ''">
  23. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  24. </el-breadcrumb-item>
  25. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  26. </el-breadcrumb>
  27. </div>
  28. </div>
  29. <section class="img_ul_box clearfix">
  30. <div class="img_li slow_6" v-for="(item, index) in newsList" :key="index">
  31. <NuxtLink class="img_li_a clearfix" :href="getLinkPathDetail(item)" :title="item.title">
  32. <h4 class="img_li_h4 dot1">{{ item.title }}</h4>
  33. <div class="img_li_in clearfix">
  34. <div class="img_li_left">
  35. <div class="img_li_left_foto_box">
  36. <img class="img_li_left_foto" :src="item.imgurl" :title="item.title"
  37. :alt="item.title">
  38. </div>
  39. <div class="img_li_left_dot1 dot1">{{ item.title }}</div>
  40. </div>
  41. <div class="img_li_right">
  42. <div class="img_li_right_dot5 dot5">
  43. {{ item.description }}
  44. </div>
  45. <div class="img_li_right_detail">【查看详情】</div>
  46. </div>
  47. </div>
  48. </NuxtLink>
  49. </div>
  50. <div class="empty" v-if="newsList == false">
  51. <img src="@/public/topic/empty.png" alt="" class="empty_img">
  52. <span class="empty_text">当前暂无数据</span>
  53. </div>
  54. </section>
  55. <!-- 分页器 -->
  56. <div class="pagination" v-if="total > 0">
  57. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  58. :page-size="pageSize" :current-page="pageNum" prev-text="上一页" next-text="下一页"
  59. @current-change="changePage" />
  60. </div>
  61. </main>
  62. <!-- 列表页广告二 -->
  63. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  64. <!-- 页面底部 -->
  65. <HomeFoot1></HomeFoot1>
  66. </div>
  67. </template>
  68. <script setup>
  69. //1.页面必备依赖 start ---------------------------------------->
  70. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  71. import { ArrowRight } from '@element-plus/icons-vue'
  72. import { ref, onMounted } from 'vue';
  73. //1.页面必备依赖 end ---------------------------------------->
  74. //2.路径 start---------------------------------------->
  75. //当前列表名称
  76. const route = useRoute();
  77. let articleId = 0;//列表需要使用的导航id
  78. let routeName;
  79. const targetSegment = getRoutePath(1);//根据路由反向查询导航id
  80. const targetSegment1 = getRoutePath(2);//根据路由反向查询导航id
  81. let pageNum = ref(1);//获得路由里面的分页数据
  82. //通过导航路径反向查询导航id
  83. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  84. method: 'GET',
  85. query: {
  86. 'pinyin': targetSegment + '/' + targetSegment1,
  87. },
  88. });
  89. if (getRouteId.code == 200) {
  90. articleId = getRouteId.data.category_id
  91. routeName = getRouteId.data.alias
  92. } else {
  93. console.log("后端错误反馈:", getRouteId.message)
  94. }
  95. pageNum.value = parseInt(route.params.id);
  96. //2.路径 end---------------------------------------->
  97. //3.列表 start ---------------------------------------->
  98. let total = ref(0);
  99. let pageSize = ref(15);
  100. const newsList = ref([]);
  101. let newslists = async () => {
  102. const listData = await requestDataPromise('/web/getWebsiteProjectList', {
  103. method: 'GET',
  104. query: {
  105. 'page': pageNum.value,
  106. 'pageSize': pageSize.value,
  107. 'category_id': articleId
  108. },
  109. });
  110. console.log("listData1111", listData);
  111. if (listData.code == 200) {
  112. newsList.value = listData.data.rows;
  113. total.value = listData.data.count;
  114. } else {
  115. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  116. console.log("错误位置:获取新闻列表")
  117. console.log("后端错误反馈:", listData.message)
  118. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  119. }
  120. }
  121. newslists();
  122. //分页
  123. let changePage = (value) => {
  124. console.log("当前页码", value);
  125. navigateTo(`/${targetSegment1}/${value}.html`)
  126. }
  127. //3.列表 end ---------------------------------------->
  128. //4.面包屑 start---------------------------------------->
  129. //3.1 获得页面名称
  130. const name = ref('')
  131. let getPageName = async () => {
  132. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  133. method: 'GET',
  134. query: {
  135. 'catid': articleId
  136. },
  137. });
  138. if (pageName.code == 200) {
  139. name.value = pageName.data.alias
  140. } else {
  141. console.log("错误位置:设置页面标题")
  142. }
  143. }
  144. getPageName();
  145. //3.2 获得父级栏目
  146. const parent_name = ref([]);
  147. const parent_id = ref([]);
  148. const parent_pinyin = ref("");
  149. let getParentNav = async () => {
  150. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  151. method: 'GET',
  152. query: {
  153. 'catid': articleId
  154. },
  155. });
  156. if (listData.code == 200) {
  157. console.log(111999)
  158. console.log(listData.data);
  159. parent_name.value = listData.data.parent_name;
  160. parent_id.value = listData.data.parent_id;
  161. parent_pinyin.value = listData.data.parent_pinyin;
  162. } else {
  163. console.log("错误位置:获取父级栏目")
  164. }
  165. getSecondNav();
  166. }
  167. getParentNav();
  168. // 3.3获取二级栏目
  169. const secondNav = ref([]);
  170. let getSecondNav = async () => {
  171. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  172. method: 'GET',
  173. query: {
  174. 'placeid': 1,
  175. 'pid': parent_id.value,
  176. 'num': 20,
  177. },
  178. });
  179. console.log('listData', listData);
  180. if (listData.code == 200) {
  181. secondNav.value = listData.data;
  182. } else {
  183. console.log("错误位置:获取二级栏目列表")
  184. }
  185. }
  186. //4.面包屑 end ---------------------------------------->
  187. //5.设置seo信息 start---------------------------------------->
  188. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  189. method: 'GET',
  190. query: {
  191. 'catid': articleId
  192. },
  193. });
  194. if (setData.code == 200) {
  195. let seoTitle = setData.data.seo_title;
  196. let seoDescription = setData.data.seo_description;
  197. let seoKeywords = setData.data.seo_keywords;
  198. let seoSuffix = setData.data.suffix;
  199. let seoName = setData.data.website_name;
  200. useSeoMeta({
  201. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  202. meta: [
  203. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  204. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  205. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  206. ]
  207. });
  208. } else {
  209. console.log("错误位置:设置列表页面SEO数据")
  210. }
  211. //5.设置seo信息 end---------------------------------------->
  212. //6.广告 start---------------------------------------->
  213. let adImg1 = ref({});
  214. let adImg2 = ref({});
  215. onMounted(async () => {
  216. //从客户端获取行政职能部门 加快打开速度
  217. const { $webUrl, $CwebUrl } = useNuxtApp();
  218. //广告1
  219. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_list_0001`
  220. const responseAd1 = await fetch(url, {
  221. headers: {
  222. 'Content-Type': 'application/json',
  223. 'Userurl': $CwebUrl,
  224. 'Origin': $CwebUrl
  225. }
  226. });
  227. const resultAd1 = await responseAd1.json();
  228. adImg1.value = resultAd1.data[0];
  229. //广告2
  230. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmgw_list_0002`
  231. const responseAd2 = await fetch(url2, {
  232. headers: {
  233. 'Content-Type': 'application/json',
  234. 'Userurl': $CwebUrl,
  235. 'Origin': $CwebUrl
  236. }
  237. });
  238. const resultAd2 = await responseAd2.json();
  239. adImg2.value = resultAd2.data[0];
  240. })
  241. //6.广告 end---------------------------------------->
  242. </script>
  243. <style lang="less" scoped>
  244. @import url('@/assets/css/project/list.less');
  245. </style>